﻿namespace Helpers.Common
{
    public abstract class ResponseMessageTemplate<DataType> : Response<DataType>
    {
        #region Properties

        public string messageTemplate { get; protected set; }
        protected string MessageTemplate
        {
            get { return this.messageTemplate; }
            set
            {
                this.messageTemplate = value;

                this.UpdateMessage();
            }
        }

        #endregion

        protected ResponseMessageTemplate()
            : this("") { }
        protected ResponseMessageTemplate(string messageTemplate)
            : this(messageTemplate, false) { }
        protected ResponseMessageTemplate(string messageTemplate, bool success)
            : base(success, "")
        {
            this.MessageTemplate = messageTemplate;
        }

        #region Methods

        protected virtual void UpdateMessage() { }
        protected virtual void UpdateMessage(params object[] parameters)
        {
            this.Message = string.Format(this.MessageTemplate, parameters);
        }

        #endregion
    }

    public class ResponseMessageTemplate : Response
    {
        #region Properties

        public string messageTemplate { get; protected set; }
        protected string MessageTemplate
        {
            get { return this.messageTemplate; }
            set
            {
                this.messageTemplate = value;

                this.UpdateMessage();
            }
        }

        #endregion

        public ResponseMessageTemplate(string message)
            : base(message) { }
        public ResponseMessageTemplate(string argumentName, string messageTemplate)
            : base(messageTemplate) { }

        #region Methods

        protected virtual void UpdateMessage() { }
        protected virtual void UpdateMessage(params object[] parameters)
        {
            this.Message = string.Format(this.MessageTemplate, parameters);
        }

        #endregion
    }
}